package com.test.vue.controller;

import com.github.pagehelper.PageInfo;
import com.test.vue.entity.BusStudent;
import com.test.vue.service.StudentService;
import com.test.vue.utils.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping(value = "/student")
public class StudentController {

    @Autowired
    StudentService studentService;

    @RequestMapping(value = "/search")
    public ResultEntity search(@RequestParam(required = true) Integer pageNo,@RequestParam(required = true) Integer pageSize,@RequestParam(required = false) String id,@RequestParam(required = false) String status){
        System.out.println(pageNo);
        System.out.println(pageSize);
        System.out.println(id);
        System.out.println(status);
        BusStudent busStudent = new BusStudent();
        PageInfo result = studentService.search(busStudent);

        return ResultEntity.findOk(result);
    }

    @GetMapping(value = "/create")
    public String create(@RequestParam(required = true) String name,@RequestParam(required = true) int age,@RequestParam(required = true) String address,@RequestParam(required = true) String banji){
        String result = "";
        BusStudent busStudent = new BusStudent();
        busStudent.setName(name);
        busStudent.setAge(age);
        busStudent.setAddress(address);
        busStudent.setBanji(banji);
        int num = studentService.create(busStudent);
        if(num > 0){
            result = "创建成功";
        }else{
            result = "创建失败";
        }
        return result;
    }


}
